<template>
	<view>
		<Tab text="新建文章" @tap="editArticle(0)"></Tab>
		<view class="article-list">
			<template v-if="articleList.length">
				<ArticleItem v-for="(item,index) in articleList" :info="item" :key="index" @tap="editArticle(item._id)">
				</ArticleItem>
			</template>
			<Empty v-else text="空空如也,开始创作吧~"></Empty>
		</view>
	</view>
</template>

<script>
	import Tab from '../../components/Tab.vue'
	import Empty from '../../components/Empty.vue'
	import ArticleItem from '../../components/ArticleItem.vue'

	import {
		request
	} from '../../utils/request.js'
	import {
		blogList
	} from '../../api.js'

	export default {
		data() {
			return {
				articleList: []
			}
		},
		components: {
			Tab,
			Empty,
			ArticleItem
		},
		onShow() {
			// let list = getApp().globalData.articleList

			// this.articleList = [...list]
			request(blogList, {
				openid: getApp().globalData.openid,
				is_self: true
			}).then(ret => {
				this.articleList = [...ret.data.list]
			})
		},
		methods: {
			editArticle(articleId) {
				uni.navigateTo({
					url: `../edit/edit?articleId=${articleId}`
				})
			}
		}
	}
</script>

<style>

</style>
